﻿using ff14bot;
using ff14bot.Managers;
using ff14bot.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ff14bot.Objects;

namespace MoreDots.HealManager
{
    public class HealingManager
    {   
        public List<PartyMember> Tanks 
        {
            get
            {
                return PartyManager.AllMembers.Where(r => r.IsTank()).ToList(); 
            }
        }

        public List<PartyMember> Healers
        {
            get
            {
                return PartyManager.AllMembers.Where(r => r.IsHealer()).ToList();
            }
        }

        public List<PartyMember> DPS
        {
            get
            {
                return PartyManager.AllMembers.Where(r => r.IsDPS()).ToList();
            }
        }

        public GameObject GetHealTarget()
        {
            var _tanks = Tanks;
            if (_tanks.Any(r => r != null && r.CurrentHealth < r.MaxHealth))
            {
                return _tanks.Select(x => x.GameObject).Where(y => y.CurrentHealth <= y.MaxHealth).OrderBy(z => z.CurrentHealth / z.MaxHealth).First();
            }
            var _healers = Healers;
            if (_healers.Any(r => r != null && r.CurrentHealth < r.MaxHealth))
            {
                return _healers.Select(x => x.GameObject).Where(y => y.CurrentHealth <= y.MaxHealth).OrderBy(z => z.CurrentHealth / z.MaxHealth).First();
            }
            var _dps = DPS;
            if (_dps.Any(r => r != null && r.CurrentHealth < r.MaxHealth))
            {
                return _dps.Select(x => x.GameObject).Where(y => y.CurrentHealth <= y.MaxHealth).OrderBy(z => z.CurrentHealth / z.MaxHealth).First();
            }
            return Core.Player;
        }
    }
}
